﻿using System;
using System.Collections.Generic;
using System.Linq;
using Salary.Domain;
using Salary.Dto;

namespace Salary.Services
{
    public class EmployeeService
    {
        private readonly IRepository<Employee> _employeesRepository;

        public EmployeeService(IRepository<Employee> employeesRepository)
        {
            _employeesRepository = employeesRepository;
        }

        public virtual List<EmployeeDto> GetEmployees()
        {
            return _employeesRepository.AsQueryable()
                .Select(x => new EmployeeDto
                {
                    Id = x.Id,
                    Name = x.Name,
                    Contacts = x.Contacts,
                    Rate = x.Rate,
                    Category = x.Position.Category,
                    PositionName = x.Position.Name,
                    Percents = x.Position.Percents
                }).ToList();
        }

        public virtual EmployeeDto GetEmployeeById(Guid employeeId)
        {
            var employee = _employeesRepository.Get(employeeId);
            return new EmployeeDto
            {
                Id = employeeId,
                Name = employee.Name,
                Contacts = employee.Contacts,
                Rate = employee.Rate,
                Category = employee.Position.Category,
                PositionName = employee.Position.Name,
                Percents = employee.Position.Percents
            };
        }
    }
}
